<!--
 * @Author: '421666927@qq.com' '421666927@qq.com'
 * @Date: 2024-09-07 13:38:52
 * @LastEditors: '421666927@qq.com' '421666927@qq.com'
 * @LastEditTime: 2024-09-07 18:10:48
 * @FilePath: \come-home-HarmonyOS-NEXT\entry\src\main\resources\rawfile\test.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
    <title>Document</title>
    <style>
      img {
        width: 100px;
        height: 100px;
      }
    </style>
  </head>
  <body>
    <div onclick="myClick()">获取图片</div>
    <div onclick="myNativeClick()">调用原生方法</div>

    <img
      alt=""
      id="myImg"
      src="https://pics0.baidu.com/feed/b58f8c5494eef01f4586bad20d800b2bbd317da0.jpeg@f_auto?token=7b0031cb7bcabba021743c82e2b0b08e"
    />
    <video
      id="myVideo"
      src="file://media/Photo/2/VID_1725700744_000/cs7b6.mp4"
    ></video>
  </body>
</html>

<script>
  let img = document.getElementById("myImg");
  let vid = document.getElementById("myVideo");
  console.log(img);
  img.src =
    "file://com.example.mashangdaojia/file%3A//media/Photo/3/IMG_1725700753_001/shop2.png";
  function myClick() {
    alert("2");
    let src = getImg.fn1();
    img.src = src;
    vid.src = src;
    console.log(img);
    alert(img);
  }
  function myNativeClick() {
    getImg.fn2();
  }

  function pathToUrl(filePath) {
    // 如果路径已经是URL，则直接返回
    if (filePath.match(/^https?:\/\//)) {
      return filePath;
    }

    // 创建一个新的URL对象，如果路径是相对的，
    // 它会相对于当前页面的URL
    const url = new URL(filePath, window.location.href);

    // 返回格式化的URL字符串
    return url.href;
  }

  // 使用示例
  const filePath = "file://media/Photo/2/VID_1725700744_000/cs7b6.mp4";
  const url = pathToUrl(filePath);
  console.log(url);
  console.log(file.toURL(filePath))
</script>
